package com.hyt.it.ogt.controller.pj;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hyt.common.apiInfor.ApiResponse;
import com.hyt.it.ogt.controller.base.BaseController;
import com.hyt.it.ogt.pj.common.Constants;
import com.hyt.it.ogt.pj.common.ResponseCode;
import com.hyt.it.ogt.pj.model.entity.Student;
import com.hyt.it.ogt.pj.service.IStudentService;
import com.hyt.model.PageParam;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSort;
import io.swagger.annotations.ApiSort;

/**
 * <p>
 * 考生表 前端控制器
 * </p>
 *
 * @author qiaozj
 * @since 2020-07-09
 */
@ApiSort(value = 6)
@Api(tags = "6.考生接口", value = "考生接口")
@RestController
@RequestMapping("/student")
public class StudentController extends BaseController {

    @Autowired
    private IStudentService studentService;

    @ApiOperationSort(value = 1)
    @ApiOperation(value = "6.1.1根据id获取考生", notes = Constants.SWAGGER_METHOD_NOTES)
    @GetMapping("query/{id}")
    public Object query(@PathVariable("id") String id){
        Student student = studentService.getById(id);
        if(student != null){
            return ApiResponse.builder().code(ResponseCode.SUCCESS).data(student).build();
        }else{
            return ApiResponse.builder().code(ResponseCode.ERROR).build();
        }
    }

    @ApiOperationSort(value = 2)
    @ApiOperation(value = "6.1.2获取指定评卷状态考生", notes = "20000成功")
    @GetMapping("selectStudent")
    public Object selelctStudent(PageParam<Student> pageParam, @RequestParam("projectId") String projectId, @RequestParam("studentName") String studentName, @RequestParam("status")String status){
        IPage<Student> page = pageParam;
        page = studentService.selectStudent(pageParam,projectId, status, studentName);
        return ApiResponse.builder().code(ResponseCode.SUCCESS).data(page).build();
    }

    @ApiOperationSort(value = 10)
    @ApiOperation(value = "6.2.1添加考生", notes= Constants.SWAGGER_METHOD_NOTES)
    @GetMapping("add")
    public Object add(@RequestBody Student student){
        Boolean flag = studentService.save(student);
        if(flag){
            return ApiResponse.builder().code(ResponseCode.SUCCESS).build();
        }else{
            return ApiResponse.builder().code(ResponseCode.ERROR).build();
        }
    }

    @ApiOperationSort(value = 20)
    @ApiOperation(value = "6.3.1更新考生", notes = Constants.SWAGGER_METHOD_NOTES)
    @PutMapping("update")
    public Object update(@RequestBody Student student){
        boolean flag = studentService.updateById(student);
        if(flag){
            return ApiResponse.builder().code(ResponseCode.SUCCESS).build();
        }else{
            return ApiResponse.builder().code(ResponseCode.ERROR).build();
        }
    }

    @ApiOperationSort(value = 30)
    @ApiOperation(value = "6.4.1根据id删除考生", notes = Constants.SWAGGER_METHOD_NOTES)
    @DeleteMapping("delete/{id}")
    public Object delete(@PathVariable("id") String id){
        boolean flag = studentService.removeById(id);
        if(flag){
            return ApiResponse.builder().code(ResponseCode.SUCCESS).build();
        }else{
            return ApiResponse.builder().code(ResponseCode.ERROR).build();
        }
    }

}
